---
title: 'Enrich with OpenTelemetry API'
sidebarTitle: 'Enrichment'
icon: 'telescope'
---

import EnrichmentIntro from '/snippets/enrichment-intro.mdx'

<EnrichmentIntro language='Java' />

## Required Dependencies

Add the following dependencies to your project:

<Tabs>
<Tab title="Maven">
```xml
<project>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>io.opentelemetry</groupId>
                <artifactId>opentelemetry-bom</artifactId>
                <version>1.35.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-api</artifactId>
        </dependency>
    </dependencies>
</project>
```
</Tab>
<Tab title="Gradle">
```groovy
dependencyManagement {
    imports {
        mavenBom("io.opentelemetry:opentelemetry-bom:1.35.0")
    }
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web");
implementation("io.opentelemetry:opentelemetry-api");
}

````

If you are not using Spring and its `io.spring.dependency-management` dependency management plugin, install the OpenTelemetry BOM and API using Gradle dependencies only.

```groovy
dependencies {
    implementation(platform("io.opentelemetry:opentelemetry-bom:1.35.0"));
    implementation("io.opentelemetry:opentelemetry-api");
}
````

</Tab>
</Tabs>

## Creating Spans

To create a span, use the `Tracer` interface. The `Tracer` interface is the main entry point for the OpenTelemetry API. It allows you to create spans and manage the current span.
Acquire a `Tracer` instance using the `OpenTelemetry` class:

```java
import io.opentelemetry.api.GlobalOpenTelemetry;

Tracer tracer = GlobalOpenTelemetry.getTracer("instrumentation-scope-name", "instrumentation-scope-version");
```

Now you can create a span using the `Tracer` instance:

```java
Span span = tracer.spanBuilder("span-name").startSpan();

try (Scope scope = span.makeCurrent()) {
    // Your code goes here.
} finally {
    span.end();
}
```

## Additional Information

For more use cases, see the [OpenTelemetry Java API documentation](https://opentelemetry.io/docs/languages/java/instrumentation/#create-spans).
